package com.hc.acoustics.ui.activity

import android.content.Intent
import android.os.Bundle
import com.hc.acoustics.R
import com.hc.acoustics.base.BaseActivity
import com.hc.acoustics.util.FormulaUtil
import com.yc.yclibrary.base.YcAppCompatActivity
import kotlinx.android.synthetic.main.formula_button.*
import kotlinx.android.synthetic.main.type6_formula1_location_activity.*
import kotlinx.android.synthetic.main.type6_formula2_location_activity.*
import java.lang.NumberFormatException

/**
 *  系统设计6 - 线阵列近场距离
 */
class Type6Formula1Activity : BaseActivity() {

    companion object {
        private const val KEY_TITLE = "key_title"
        @JvmStatic
        fun newInstance(activity: YcAppCompatActivity, title: String) {
            val intent = Intent(activity, Type6Formula1Activity::class.java)
            intent.putExtra(KEY_TITLE, title)
            activity.startActivity(intent)
        }
    }

    override fun getLayoutId(): Int {
        return R.layout.type6_formula1_location_activity
    }

    override fun initView(savedInstanceState: Bundle?) {
        setActionBar(intent.getStringExtra(KEY_TITLE))
        formulaResetBtn.setOnClickListener {
            formula6_1_t_TEV.reset()
            formula6_1_v_TEV.reset()
            formula6_1_l_TEV.reset()
            formula6_1_f_TEV.reset()
            formula6_1_m_TEV.reset()
        }
        formulaOkBtn.setOnClickListener {
            try {
                val resultV = FormulaUtil.formula6_1_1(formula6_1_t_TEV.getDouble())
                val resultM = FormulaUtil.formula6_1_2(
                    formula6_1_l_TEV.getDouble(),
                    formula6_1_f_TEV.getDouble(),
                    resultV
                )
                formula6_1_v_TEV.setText(resultV)
                formula6_1_m_TEV.setText(resultM)
            } catch (e: NumberFormatException) {
                formula6_1_v_TEV.setText("Infinity")
                formula6_1_m_TEV.setText("Infinity")
            }
        }
    }
}